
Module modProcess


    Public Sub Start()
        Dim sFuncname As String = "Start"
        Uploadfiles()

        'Send Error Email if Datable has rows
        If p_oDtError.Rows.Count > 0 Then
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Calling EmailTemplate_Error()", sFuncName)
            EmailTemplate_Error()
        End If
        p_oDtError.Rows.Clear()

    End Sub

    Private Sub Uploadfiles()

        Dim sFuncName As String = "Uploadfiles()"
        Dim sErrDesc As String = String.Empty

        Try
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Starting Function..", sFuncName)

            p_oDtError = CreateDataTable("FileName", "Status", "ErrDesc")

            '*************************** CUSTOMER *******************************************
            'CMS
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("CMS SubFolder - Calling Function UploadCUSTOMER()", sFuncName)
            If UploadCUSTOMER("CMS", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the Customer csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If
            'AMPHARMA
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("AMPHARM SubFolder - Calling Function UploadCUSTOMER()", sFuncName)
            If UploadCUSTOMER("AMPHARM", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the Customer csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            '**************************** SUPPLIER *******************************************

            'CMS
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("CMS Sub Folder - Calling Function UploadSUPPLIER()", sFuncName)
            If UploadSUPPLIER("CMS", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the Customer csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If
            'AMPHARM
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("AMPHARM SubFolder - Calling Function UploadSUPPLIER()", sFuncName)
            If UploadSUPPLIER("AMPHARM", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the Customer csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            '************************************ AR *******************************************
            'CMS
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("CMS Sub Folder - Calling Function UploadAR()", sFuncName)
            If UploadAR("CMS", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the AR csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            'AMPHARM
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("CMS Sub Folder - Calling Function UploadAR()", sFuncName)
            If UploadAR("AMPHARM", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the AR csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            '************************************ INTERCO *******************************************

            'CMS
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("CMS Sub Folder - Calling Function UploadINTERCO()", sFuncName)
            If UploadINTERCO("CMS", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the AR csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            'AMPHARM
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("AMPHARM Sub Folder - Calling Function UploadINTERCO()", sFuncName)
            If UploadINTERCO("AMPHARM", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the AR csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            '********************************* AP *******************************************

            'CMS
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("CMS sub Folder - Calling Function UploadAP()", sFuncName)
            If UploadAP("CMS", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the AP csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            'AMPHARM
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("AMPHARM sub Folder - Calling Function UploadAP()", sFuncName)
            If UploadAP("AMPHARM", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the AP csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If

            '***************** POS *******************************************
            'POS ---- AMPHARM
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("AMPHARM sub Folder - Calling Function UploadPOS()", sFuncName)
            If UploadPOS("AMPHARM", sErrDesc) <> RTN_SUCCESS Then
                If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error occured while Uploading the POS csv files", sFuncName)
                WriteToLogFile(sErrDesc, sFuncName)
            End If


        Catch ex As Exception
            If p_iDebugMode = DEBUG_ON Then Call WriteToLogFile_Debug("Error in upload setup", sFuncName)
            Call WriteToLogFile(ex.Message, sFuncName)
        End Try
    End Sub



End Module
